home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programmer Power Tools
/
Programmer Power Tools.iso
/
c
/
jazlib.arc
/
DIRLST.DMO
< prev
next >
Wrap
Text File
|
1986-07-20
|
3KB
|
120 lines
/*
┌────────────────────────────────────────────────────────────────────────────┐
│dirlst.c │
│Demo of directory routines │
│ │
│Usage: dirlst *.c │
│ │
│ │
│ (C) JazSoft Software by Jack A. Zucker (301) 794-5950 │
└────────────────────────────────────────────────────────────────────────────┘
*/
#include "jzdirect.h"
#include "jaz.h"
struct dir {
unsigned char attr; /* file attribute */
struct tdirtime time; /* creation time */
struct tdirdate date; /* creation date */
long size; /* file size */
char name[13]; /* file name */
};
struct tree {
struct dir wdir;
struct tree *pleft,*prite;
};
#define TREE struct tree
int wcount = 0;
main(argc,argv)
int argc;
char **argv;
{
char wname[50];
TREE *whead,*insert();
int werr;
TDIR wlist;
TFAT wfat;
if (argc != 2) strcpy(wname,"*.*");
else strcpy(wname,argv[1]);
whead = 0;
werr = jzfndfst(wname,32,&wlist);
if (! werr) {
do {
whead = insert(whead,wlist);
werr = jzfndnxt(&wlist);
} while ( ! werr);
treeprint(whead);
jzdskfre(&wfat,0);
printf("\n%9d File(s) %9ld bytes free",wcount,wfat.free);
printf("\n%9s %9ld bytes used","",wfat.used);
printf("\n%9s %9ld total space","",wfat.total);
}
else printf("\nNo match for %s",argv[1]);
}
TREE *insert(fptr,fdir)
TREE *fptr;
TDIR fdir;
{
if (fptr == 0) { /* install new wdir name */
fptr = (TREE *) malloc(sizeof(TREE));
strcpy(fptr->wdir.name,fdir.name);
fptr->wdir.attr = fdir.attr;
fptr->wdir.time = fdir.time;
fptr->wdir.date = fdir.date;
fptr->wdir.size = fdir.size;
fptr->pleft = fptr->prite = 0;
}
else
if (strcmp(fptr->wdir.name,fdir.name) > 0)
fptr->pleft = insert(fptr->pleft,fdir);
else
fptr->prite = insert(fptr->prite,fdir);
return(fptr);
}
static int c_ampm[] = { 'a','p' };
treeprint(p)
TREE *p;
{
char wname[13],wext[4];
char whour,windex;
int wch;
if (p) {
treeprint(p->pleft);
windex = p->wdir.time.hours > 12;
whour = p->wdir.time.hours % 12;
if (! whour) whour = 12;
if (++wcount % 24 == 0) {
printf("\nHit <ENTER> to continue...");
do ; while ((wch = getch() != '\r'));
}
if (strchr(p->wdir.name,'.')) {
jzgetpce(p->wdir.name,wname,'.',1);
jzgetpce(p->wdir.name,wext,'.',2);
}
else {
strcpy(wname,p->wdir.name);
*wext = 0;
}
sprintf(p->wdir.name,"%-8s %-3s",wname,wext);
printf("\n%-12s %7ld %2d-%02d-%02d %2d:%02d%c",
p->wdir.name,p->wdir.size,
p->wdir.date.month,p->wdir.date.day,p->wdir.date.year,
whour,p->wdir.time.mins,c_ampm[windex]);
treeprint(p->prite);
}
}